
public class Test {
    public static void main(String[] args) {
        // 要枚举一个JavaBean的所有属性，可以直接使用Java核心库提供的Introspector
        try {
            java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(Person.class);
            java.beans.PropertyDescriptor[] props = info.getPropertyDescriptors();
            for (java.beans.PropertyDescriptor prop : props) {
                System.out.println("Property name: " + prop.getName());
                System.out.println("Property type: " + prop.getPropertyType());
                System.out.println("Read method: " + prop.getReadMethod());
                System.out.println("Write method: " + prop.getWriteMethod());
                System.out.println("-----");
            }
        } catch (java.beans.IntrospectionException e) {
            e.printStackTrace();
        }
    }
}

// JavaBean
// 使用 getter和setter 方法来访问私有属性
class Person {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}